package org.jeecg.trace.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.basic.entity.MesLineCfg;
import org.jeecg.common.api.vo.Result;
import org.jeecg.trace.dto.ProductionTraceDTO;
import org.jeecg.trace.service.ProductionTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.util.Map;

@Api(tags = "生产历史追溯")
@RestController
@RequestMapping("/trace/productionTrace")
@Slf4j
public class ProductionTraceController {
    @Autowired
    private ProductionTraceService productionTraceService;


    /**
     * 分页列表查询  erp
     *
     * @param map
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "序列号列表-分页列表查询")
    @ApiOperation(value = "序列号列表-分页列表查询", notes = "序列号列表-分页列表查询")
    @GetMapping(value = "/list")
    @DS("#header.his")
    public Result<IPage<ProductionTraceDTO>> queryList(@RequestParam Map<String, String> map,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       HttpServletRequest req) {
        Page<ProductionTraceDTO> page = new Page<>(pageNo, pageSize);
        IPage<ProductionTraceDTO> pageList = productionTraceService.queryList(page, map);
        return Result.OK(pageList);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param map
     */
    //@RequiresPermissions("org.jeecg.basic.demo:mes_line_cfg:exportXls")
    @RequestMapping(value = "/exportXls")
    @DS("#header.his")
    public void exportXls(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> map) {
        productionTraceService.exportXls(request,response, map);
    }

    /**
     * 导出excel测试
     *
     * @param request
     */
    @RequestMapping(value = "/export")
    @DS("#header.his")
    public ModelAndView export(HttpServletRequest request) {
        //先来看看桌面路径
        FileSystemView systemView = FileSystemView.getFileSystemView();
        File defaultDirectory = systemView.getDefaultDirectory();
        File homeDirectory = systemView.getHomeDirectory();
        //桌面路径
        String path = homeDirectory.getPath();
        System.out.println(path+"-----------------");

        return null;
    }

}
